<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        // 计算器构造函数
        function Calculator(num1, num2) {
            this.sum = (a = num1, b = num2) => a + b;
            this.sub = (a = num1, b = num2) => a - b;
            this.mul = (a = num1, b = num2) => a * b;
            this.div = (a = num1, b = num2) => {
                if (num2 === 0) return undefined;
                return a / b;
            }
        }

        // 测试
        let c = new Calculator(); // 看这里！计算器是new出来的！
        let num1 = prompt("第一个数：");
        let num2 = prompt("第二个数：");
        switch (prompt("运算符号（记得输英文）：")) {
            case "+":
                alert(c.sum(num1, num2));
                break;
            case "-":
                alert(c.sub(num1, num2));
                break;
            case "*":
                alert(c.mul(num1, num2));
                break;
            case "/":
                alert(c.div(num1, num2));
                break;
            default:
                alert("没见过的运算符号");
        }
    </script>
</head>
<body>
<div id="root"></div>
</body>
</html>